cd "/Users/alee87/Dropbox/Job Reservation/Replication"
use "casteDHSworking copy.dta", clear
drop if state==""
keep if hv105<40

gen period=0
replace period =1 if year>1993


replace stategrp =. if obc_res_year==.

gen castgrp=0
replace castgrp=1 if category=="obc"

gen int_obc=castgr 
gen int_post94=period
gen int_northstate=stategr
gen int_obc_north=castgr *stategr
gen int_obc_post94=castgr*period
gen int_north_post94=stategr*period
gen int_north_obc_post=castgr *stategr*period

label var  int_obc "OBC Caste"
label var  int_post94  "Post 1994"
label var  int_northstate  "Mandal State"
label var  int_obc_north  "OBC Caste*Mandal State"
label var  int_obc_post94  "OBC*Post 94"
label var  int_north_post94  "Post 94*Mandal State"
label var  int_north_obc_post "OBC*Post 94*Mandal State"

gen yearsofeducation=.
replace yearsofeducation=0 if hv106==0
replace yearsofeducation=hv107 if hv106==1
replace yearsofeducation=hv107+5 if hv106==2 &year!=1993
replace yearsofeducation=hv107+7 if hv106==2 &year==1993
replace yearsofeducation=hv107+12 if hv106==3

gen professional_managerial_man=.
replace professional_managerial_man=0 if v704<98 &year==1993
replace professional_managerial_man=1 if v704<4 &year==1993
replace professional_managerial_man=. if v704==0 &year==1993

replace professional_managerial_man=. if v705==0 &year==1993
replace professional_managerial_man=1 if v705==1 &year!=1993
replace professional_managerial_man=0 if v705>1 &year!=1993
replace professional_managerial_man=. if v705>97 &year!=1993

gen professional_managerial_woman=.
replace professional_managerial_woman=0 if v716<98 &year==1993
replace professional_managerial_woman=1 if v716<4 &year==1993
replace professional_managerial_woman=. if v716==0 &year==1993

replace professional_managerial_woman=. if v717==0 &year!=1993
replace professional_managerial_woman=1 if v717==1 &year!=1993
replace professional_managerial_woman=0 if v717>1 &year!=1993
replace professional_managerial_woman=. if v717>97 &year!=1993



egen hhid_new=group(state year hv001 hv002)

egen state_category_id=group(state category)
egen year_category_id=group(year category)
egen year_state_id=group(year state)




reg yearsofeducation  int_obc   int_post94 int_obc_post94 [ pweight= hv005] if  int_northstate==1, vce(cluster hhid_new)
outreg2 using education_dhs,  keep( int_obc   int_post94 int_obc_post94 )  addtext( State-Caste Category FE, NO, Year-State FE, NO, Caste Category-Year FE, NO) replace label nocon
reg yearsofeducation   i.state_category_id i.year_state_id int_obc_post94 [ pweight= hv005] if  int_northstate==1, vce(cluster hhid_new)
outreg2 using education_dhs,  keep(int_obc   int_obc_post94 )  addtext(  State-Caste Category FE, YES, Year-State FE, YES, Caste Category-Year FE, NO) append label nocon

reg yearsofeducation  int_obc int_post94 int_northstate int_obc_north int_obc_post94 int_north_post94 int_north_obc_post [ pweight= hv005]  , vce(cluster hhid_new)
outreg2 using education_dhs,  keep( int_obc int_post94 int_northstate int_obc_north int_obc_post94 int_north_post94 int_north_obc_post )  addtext( State-Caste Category FE, NO, Year-State FE, NO, Caste Category-Year FE, NO) append label nocon
reg yearsofeducation    i.state_category_id i.year_category_id i.year_state_id  int_north_obc_post [ pweight= hv005], vce(cluster hhid_new)
outreg2 using education_dhs,  keep(int_obc    int_north_obc_post)  addtext(  State-Caste Category FE, YES, Year-State FE, YES, Caste Category-Year FE, YES) append tex(frag) label nocon


collapse (mean)  yearsofeducation , by(year castgr stategr)

***FIGURE A4
twoway (line years year if castgr==1&stategr==0, xline(1994, lstyle(dot)) lcolor(black) lpattern(solid )) (line years year if castgr==0&stategr==0, xline(1994)  lcolor(black ) lpattern(dash )) , legend(order(1 2 ) label(1 "OBC") label(2 "General")) scheme(s1mono) xtitle({stSerif: Year}) ytitle({stSerif: Average Years of Education}) title({stSerif:  Non-Mandal States}) xlabel(1993 1999 2006 2016)
graph2tex,  epsfile(DHSyears0) 
twoway (line years year if castgr==1&stategr==1, xline(1994, lstyle(dot)) lcolor(black) lpattern(solid )) (line years year if castgr==0&stategr==1, xline(1994)  lcolor(black ) lpattern(dash )), legend(order(1 2 ) label(1 "OBC") label(2 "General")) scheme(s1mono) xtitle({stSerif: Year}) ytitle({stSerif: Average Years of Education}) title({stSerif:  Mandal States}) xlabel(1993 1999 2006 2016)
graph2tex,  epsfile(DHSyears1) 
